﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using log4net;
using log4net.Config;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.IO;

namespace MangaManagerLib
{
    public class Logger
    {
        
        //private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
        private static Logger instance;
        public static Logger GetInstance()
        {
            if (instance == null)
            {
                instance = new Logger();
            }
            return instance;
        }
        private Logger()
        {
            try
            {
                log4net.Config.XmlConfigurator.Configure(new System.IO.FileInfo(Path.Combine(System.IO.Path.GetDirectoryName(
      System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase).Replace("file:\\", string.Empty),"log4net.config") ) );
            }
            catch (Exception ex)
            { 
            
            }
           
        }
        public void LogException(Exception ex)
        {
            StackTrace strack = new StackTrace();
            ILog log = LogManager.GetLogger(strack.GetFrame(1).GetMethod().DeclaringType);
            log.Fatal(ex);            
        }
        public void Error(object sender, Exception ex)
        {
            
            StackTrace strack = new StackTrace();
            ILog log = LogManager.GetLogger(strack.GetFrame(1).GetMethod().DeclaringType);
            log.Error(sender, ex);
            
        }
        public void Info(string Infomation)
        {
           
            StackTrace strack = new StackTrace();
            //ILog log = LogManager.GetLogger(strack.GetFrame(1).GetMethod().DeclaringType);
            ILog log = LogManager.GetLogger("MangaManagerLib");
            log.Info(Infomation);
            
        }
        public void Debug(object p, Exception ex)
        {
           
            StackTrace strack = new StackTrace();
            ILog log = LogManager.GetLogger(strack.GetFrame(1).GetMethod().DeclaringType);
            log.Debug(p, ex);
            
        }
        public void Debug(string messageBox)
        {
            
            StackTrace strack = new StackTrace();
            ILog log = LogManager.GetLogger(strack.GetFrame(1).GetMethod().DeclaringType);
            log.Debug(messageBox);
            
        }
        public void Error(string error)
        {
            
            StackTrace strack = new StackTrace();
            ILog log = LogManager.GetLogger(strack.GetFrame(1).GetMethod().DeclaringType);
            log.Error(error);
            
        }
    }
}